package com.bjsxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bjsxt.mapper.MarriedPersonMapper;
import com.bjsxt.pojo.MarriedPerson;
import com.bjsxt.pojo.PageResult;
import com.bjsxt.service.IMarriedPersonService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-10-14
 */
@Service
public class MarriedPersonServiceImpl extends ServiceImpl<MarriedPersonMapper, MarriedPerson> implements IMarriedPersonService {


    @Override
    public PageResult<MarriedPerson> selMarriedPersonInfo(Integer page, Integer rows, String pname, String pphone) {
        //创建分页条件
        IPage<MarriedPerson> page1 = new Page<>(page,rows);
        //创建wrapper构造器
        QueryWrapper<MarriedPerson> queryWrapper= new QueryWrapper<>();
        if (pname!=null&&!"".equals(pname)){
            queryWrapper.like("pname",pname);
        }
        if (pphone!=null&&!"".equals(pphone)){
            queryWrapper.eq("phone",pphone);
        }
        IPage<MarriedPerson> marriedPersonIPage = baseMapper.selectPage(page1, queryWrapper);
        List<MarriedPerson> marriedPeople = baseMapper.selectList(queryWrapper);
        PageResult<MarriedPerson> pageResult = new PageResult<>(marriedPersonIPage.getTotal(), marriedPersonIPage.getRecords());
        return pageResult;
    }
}
